# -*- coding: utf-8 -*-
import os
import sys

sys.path.append(os.getcwd())

# 加载env配置文件
from dotenv import load_dotenv

load_dotenv()

from slide_interface import create_app

# 单例模式
app = create_app()
if __name__ == '__main__':
    # 线上服务器
    app.run(host=os.getenv("HOST"), port=int(os.getenv("PORT")), workers=8, debug=True)

    # 本地测试
    # app.run(host=os.getenv("IP"), port=int(os.getenv("PORT")), workers=4, debug=False)

# 支持Mac/linux
# if __name__ == '__main__':
#     asyncio.set_event_loop(uvloop.new_event_loop())
#     server = app.create_server(host="0.0.0.0", port=8000, return_asyncio_server=True)
#     loop = asyncio.get_event_loop()
#     loop.set_task_factory(context.task_factory)
#     task = asyncio.ensure_future(server)
#     try:
#         loop.run_forever()
#     except:
#         loop.stop()


'''
sanic部署方式：
服务器部署:
内置的web服务器和 ASGI webserver 或 gunicorn => 后续配置文件即可 支持高并发等等
性能提高: cpu核数 日志管理
workers=4 ,access_log=False

命令行执行:
sanic py文件名称.app --host=0.0.0.0 --port=8000 --workers=8



'''

'''
项目启动命令:
mac/linux
sanic slide_manage.app --host=0.0.0.0 - --workers=4

clear




sanic /root/slide_server/slide_manage.app --host=0.0.0.0 --workers=8
后台运行
nohup  python /root/slide_server/slide_manage.py  > slide_serever.log  &
nohup  python /root/live_integral/manage.py  > slide_server.log  &

nohup  python /items/slide_server/slide_manage.py > slide_manage.log  &

nohup  python slide_manage.py > slide_manage.log  &


windows
python -m sanic slide_manage.app --host=0.0.0.0 --port=9999 --workers=4


python slide_manage.py --host=0.0.0.0 --port=9999

cd /var/www/items/slide_server
nohup python -m sanic manage.app   --workers=4 > slide_serever.log  &


nohup python slide_manage.py  > slide_serever.log  &


8F35BD04D885645ABC407A798E884EE3 京东h5st!!!


sudo iptables -A INPUT -p tcp --dport 9999 -j ACCEPT

'''
